package com.dimbottom.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dimbottom.entity.rest.RPage;
import com.dimbottom.entity.rest.Rest;
import com.dimbottom.entity.StudentLog;
import com.dimbottom.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "日志管理", tags = {"日志管理"})
@RestController
public class StudentLogController {

    LogService logService;

    @ApiOperation(value = "日志查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentCode", dataType = "String", paramType = "path",
                    value = "查询的学号", example = "18401010415"
            ),
            @ApiImplicitParam(name = "p", dataType = "int",
                    value = "分页当前页", example = "1"
            )
    })
    @GetMapping("/student/log/{studentCode}")
    public Rest<RPage<StudentLog>> list(@PathVariable String studentCode, int p) {
        if (p <= 0)
            p = 1;
        QueryWrapper<StudentLog> wrapper = new QueryWrapper<>();
        wrapper.eq("student_code", studentCode);
        Page<StudentLog> page = new Page<>(p, 20);
        Page<StudentLog> data = logService.page(page, wrapper);
        return RPage.ok(page);
    }

    @Autowired
    public void setLogService(LogService logService) {
        this.logService = logService;
    }
}
